#include "VolumeWidget.h"

#include "vtkRenderWindow.h"
#include "vtkCubeAxesActor.h"
#include "vtkTextProperty.h"

#include <QMessageBox>

void
VolumeWidget::SetVolume(Material *material, PolyDataPointer polyData)
{
    PolyDataMapperPointer polyDataMapper = PolyDataMapperPointer::New();
    polyDataMapper->SetScalarVisibility(0);
    polyDataMapper->SetInput(polyData);
    polyDataMapper->Update();

    ActorPointer actor;
    if (m_ActorsMap->value(material->GetLabel()) == NULL)
    {
        actor = ActorPointer::New();
        actor->GetProperty()->SetColor(material->GetColor().red()/255, material->GetColor().green()/255,
                                       material->GetColor().blue()/255);
        actor->GetProperty()->SetSpecular(.3);
        actor->GetProperty()->SetSpecularPower(20);
        actor->SetUserMatrix(m_TransformMatrix);
        m_ActorsMap->insert(material->GetLabel(), actor.GetPointer());
        m_Renderer->AddActor(static_cast<vtkActor*>(m_ActorsMap->value(material->GetLabel())));
    }
    else
        actor = static_cast<vtkActor*>(m_ActorsMap->value(material->GetLabel()));

    actor->SetMapper(polyDataMapper);
    m_Renderer->ResetCamera();

    this->Update();
}

void
VolumeWidget::DisplayBox(double x, double y, double z)
{
    vtkSmartPointer<vtkCubeAxesActor> axes = vtkCubeAxesActor::New() ;
    axes->SetBounds(0, x, 0, y, 0, z);
    axes->SetXAxisRange(0, x);
    axes->SetYAxisRange(0, y);
    axes->SetZAxisRange(0, z);
    axes->SetCamera(m_Renderer->GetActiveCamera());
    axes->SetOrigin(0,0,0);
    axes->SetUserMatrix(m_TransformMatrix);

   // axes->SetXLabelFormat( "%10.1f" );
  //  axes->SetYLabelFormat( "%6.1f" );
  //  axes->SetZLabelFormat( "%6.1f" );

  //  axes->SetFlyModeToClosestTriad();
  //  axes->SetCornerOffset( .0 );

   axes->GetXAxesLinesProperty()->SetColor(1, 0, 0);
   axes->GetTitleTextProperty(0)->SetColor(1, 0, 0);
   axes->GetLabelTextProperty(0)->SetColor(1, 0, 0);
   axes->GetTitleTextProperty(0)->SetBold(1);

   axes->GetYAxesLinesProperty()->SetColor(0, 1, 0);
   axes->GetTitleTextProperty(1)->SetColor(0, 1, 0);
   axes->GetLabelTextProperty(1)->SetColor(0, 1, 0);

   axes->GetZAxesLinesProperty()->SetColor(0, 0, 1);
   axes->GetTitleTextProperty(2)->SetColor(0, 0, 1);
   axes->GetLabelTextProperty(2)->SetOpacity(1.0);

   axes->ApplyProperties();

   m_Renderer->AddActor(axes);

   this->Update();
}






